package control;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.CommentsDao;
import dao.NewsDao;
import pojo.Comments;
import pojo.News;

public class DoShowNews extends HttpServlet {

	public DoShowNews() {
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=utf-8");
		request.setCharacterEncoding("utf-8");
		
		Integer nid=Integer.parseInt(request.getParameter("nid"));
		request.setAttribute("news", NewsDao.doSearchById(nid));
		
		List<News> newsGN = NewsDao.doSearchTopX(1);
		request.setAttribute("newsGN", newsGN);
		
		List<News> newsGJ = NewsDao.doSearchTopX(2);
		request.setAttribute("newsGJ", newsGJ);
		
		List<News> newsYL = NewsDao.doSearchTopX(3);
		request.setAttribute("newsYL", newsYL);
		
		List<Comments> comments=CommentsDao.doSearchComments(Integer.parseInt(request.getParameter("nid")));
		request.setAttribute("comments", comments);
		
		request.getRequestDispatcher("WEB-INF/jsp/news.jsp").forward(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	doGet(request, response);
	}

	public void init() throws ServletException {
		// Put your code here
	}

}
